﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ecreate.Popedom;
using Newtonsoft.Json;
namespace Ecreate.Web.popedom.usersearch
{
    public partial class data : System.Web.UI.Page
    {
        public class jsoncountry
        {
            private string _parentvalue = "";

            public string Parentvalue
            {
                get { return _parentvalue; }
                set { _parentvalue = value; }
            }
            private string _value;

            public string Value
            {
                get { return _value; }
                set { _value = value; }
            }
            private string _text;

            public string Text
            {
                get { return _text; }
                set { _text = value; }
            }


        }

        public class jsoncity
        {

            private string _parentvalue = "";

            public string Parentvalue
            {
                get { return _parentvalue; }
                set { _parentvalue = value; }
            }
            private List<jsonobject> _data = new List<jsonobject>();

            public List<jsonobject> Data
            {
                get { return _data; }
                set { _data = value; }
            }
        }


        public class jsonobject
        {

            private string _value;

            public string Value
            {
                get { return _value; }
                set { _value = value; }
            }
            private string _text;

            public string Text
            {
                get { return _text; }
                set { _text = value; }
            }
           

        }

        Ecreate.Popedom.Dao.Hibernate.AreaDaoImpl area = new Ecreate.Popedom.Dao.Hibernate.AreaDaoImpl();
        protected void Page_Load(object sender, EventArgs e)
        {

           
        }

        public string CreateProvinceData()
        {
            IList<tArea> list = area.getProvince();
            List<jsoncountry> l_country = new List<jsoncountry>();
            foreach (tArea a in list)
            {
                jsoncountry jcountry = new jsoncountry();
                jcountry.Text = a.AreaName;
                jcountry.Value = a.Id;
                jcountry.Parentvalue = a.ParentAreacode;

                l_country.Add(jcountry);
            }
            string json1 = JsonConvert.SerializeObject(l_country);
            json1 = "var data_province=" + json1 + ";";
            return json1;

        }


        public string CreateCityData()
        {
            IList<tArea> list = area.getProvince();
            List<jsonobject> l = new List<jsonobject>();
            List<jsoncity> l1 = new List<jsoncity>();
            foreach (tArea a in list)
            {
                jsoncity j = new jsoncity();
                j.Parentvalue = a.Id;
                IList<tArea> lcity = area.getCity(a.Id);
                foreach (tArea city in lcity)
                {
                    jsonobject jcity = new jsonobject();
                    jcity.Text = city.AreaName;
                    jcity.Value = city.Id;
                    j.Data.Add(jcity);
                }
                l1.Add(j);
            }
            string json1 = JsonConvert.SerializeObject(l1);
            json1 = "var data_city=" + json1 + ";";
            return json1;

        }



        public string CreateCountryData()
        {
            IList<tArea> list = area.getCity();
            List<jsoncity> l1 = new List<jsoncity>();
            foreach (tArea a in list)
            {
                jsoncity j = new jsoncity();
                j.Parentvalue = a.Id;
                IList<tArea> lcountry = area.getCountry(a.Id);
                foreach (tArea country in lcountry)
                {
                    jsonobject jcity = new jsonobject();
                    jcity.Text = country.AreaName;
                    jcity.Value = country.Id;
                    j.Data.Add(jcity);
                }
                l1.Add(j);
            }
            string json1 = JsonConvert.SerializeObject(l1);
            json1 = "var data_country=" + json1 + ";";
            return json1;
        }

    }
}
